package com.xb.p26_bindservice;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

import java.util.Random;

public class MyBindService extends Service {

    final static String TAG="MyBindService";
    IBinder iBinder;
    Random mGenerator;

    public class MyBind extends Binder {
        MyBindService getService(){
            return MyBindService.this;
        }
    }

    public MyBindService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        Log.i(TAG,"onBind");
        return iBinder;
    }

    @Override
    public void onCreate() {
        Log.i(TAG,"onCreate");
        super.onCreate();
        iBinder=new MyBind();
        mGenerator=new Random();
    }

    @Override
    public void onDestroy() {
        Log.i(TAG,"onDestroy");
        super.onDestroy();
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.i(TAG,"onUnbind");
        return super.onUnbind(intent);
    }

    @Override
    public void onRebind(Intent intent) {
        Log.i(TAG,"onRebind");
        super.onRebind(intent);
    }


    //提供一个生成随机数的方法
    public int getRandomNum(){
        return mGenerator.nextInt(100);
    }
}